﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.WindowsAzure.StorageClient;
using AutoMapper;
using CashFlow.Entities;

namespace CashFlow.AzureRepository
{
	public class TenantAzure : TableServiceEntity
	{
		public string Id { get; set; }
		public DateTime InitialBalanceDate { get; set; }
		public double InitialBalanceAmount { get; set; }

		#region Constructors
		/// <summary>
		/// Initializes a new instance of the <see cref="T:TenantAzure"/> class.
		/// </summary>
		static TenantAzure()
		{
			Mapper.CreateMap<Tenant, TenantAzure>().
				ForMember(dest => dest.PartitionKey, 	opt => opt.MapFrom(src => src.Id)).
				ForMember(dest => dest.RowKey,				opt => opt.MapFrom(src => string.Empty));

			Mapper.CreateMap<TenantAzure, Tenant>();
		}
		#endregion

		#region Mappers
		public static explicit operator TenantAzure(Tenant entity)
		{
			var model = Mapper.Map<Tenant, TenantAzure>(entity);
			return model;
		}

		public static explicit operator Tenant(TenantAzure model)
		{
			var entity = Mapper.Map<TenantAzure, Tenant>(model);
			return entity;
		}
		#endregion
	}
}
